<template>
	<div class="page-wrap">
		<div class="page-content p-0">
			<div class="page-column p-0">
				<div class="page-form p-x-0">
					<el-form
						:model="ruleForm"
						:rules="rules"
						label-position="left"
						label-width="180px"
						ref="form"
						label-suffix="："
					>
						<el-row>
							<el-col :span="24">
								<el-form-item label="计算烟摆因子的基准时间" prop="PMTIMBAS001">
									<el-input size="medium" class="mediumForm" v-model="ruleForm.PMTIMBAS001">
										<template slot="append">s</template>
									</el-input>
								</el-form-item>
							</el-col>
						</el-row>
						<el-row>
							<el-col :span="24">
								<el-form-item label="计算烟摆因子的分段时间" prop="PMBRKPNT001">
									<el-input size="medium" class="mediumForm" v-model="ruleForm.PMBRKPNT001">
										<template slot="append">s</template>
									</el-input>
								</el-form-item>
							</el-col>
						</el-row>
						<el-row>
							<el-col :span="24">
								<el-form-item label="撤离开始时间" prop="RDOALARM001">
									<el-input size="medium" class="mediumForm" v-model="ruleForm.RDOALARM001">
										<template slot="append">s</template>
									</el-input>
								</el-form-item>
							</el-col>
						</el-row>
					</el-form>
				</div>
				<div class="bottom-btn">
					<el-button type="primary" :loading="loading" @click="submitFun">下一步</el-button>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
import { v6086400, v00604800 } from "@/utils/verify.js"
import { mapState } from "vuex"
export default {
	props: {
		batchid: String,
	},
	data() {
		return {
			activeTab: "6",
			ruleForm: {
				PMTIMBAS001: "600",
				PMBRKPNT001: "3600",
				RDOALARM001: "1300",
			},
			rules: {
				PMTIMBAS001: [
					{
						validator: v6086400,
						trigger: "change",
					},
				],
				PMBRKPNT001: [
					{
						validator: v6086400,
						trigger: "change",
					},
				],
				RDOALARM001: [
					{
						validator: v00604800,
						trigger: "change",
					},
				],
			},
			loading: false,
		}
	},
	computed: {
		...mapState({
			basic_Data: (state) => state.token.basic_Data,
		}),
	},
	mounted() {
		this.setoption()
	},
	methods: {
		setoption() {
			//初始化数据
			this.ruleForm.PMTIMBAS001 = this.basic_Data.PMTIMBAS001.toString()
			this.ruleForm.PMBRKPNT001 = this.basic_Data.PMBRKPNT001.toString()
			this.ruleForm.RDOALARM001 = this.basic_Data.RDOALARM001.toString()
		},
		submitFun() {
			this.$refs.form.validate((valid) => {
				if (valid) {
					// console.log(this.basic_Data)
					let tempdata = JSON.parse(JSON.stringify(this.basic_Data))
					tempdata.PMTIMBAS001 = parseFloat(this.ruleForm.PMTIMBAS001)
					tempdata.PMBRKPNT001 = parseFloat(this.ruleForm.PMBRKPNT001)
					tempdata.RDOALARM001 = parseFloat(this.ruleForm.RDOALARM001)
					tempdata.SETPAGEINDEX = this.activeTab
					this.$store.dispatch("upData_basic_Data", tempdata)
					let params = {
						batchid: this.$props.batchid,
						batchinfo: "BASE",
						submitjson: JSON.stringify(tempdata),
					}
					this.$appApi
						.BATCH_SUBMIT(params)
						.then((res) => {
							var str = res.data.substring(0, 1)
							if (str == "E") {
								let message = res.data.substring(6)
								this.$notify.error({
									title: "保存失败！",
									message: message,
									type: "success",
								})
							} else if (str == "S") {
								this.$notify({
									message: "保存成功！",
									type: "success",
								})
								this.$emit("changeActiveTab", this.activeTab)
					            this.$store.dispatch("change_basic_showTab", this.activeTab)
								if(activeTab >=9){
									this.$router.push({
										path: "/home",
									})
								}
							}
						})
						.catch((err) => {
							console.log(err)
						})

					// console.log(this.basic_Data)
					// console.log(this.activeTab)
				}
			})
		},
	},
}
</script>
<style lang="scss" scoped>
.page-flex-row /deep/ .el-collapse-item__header {
	background: #f3f9fe;
}
</style>